package com.jerry.reflect;

import java.lang.reflect.Field;
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
import java.util.ArrayList;
import java.util.List;

/**
 * Created by Shirly on 2016/12/12.
 */
public class test8 {
    public static void main(String[] args) {
        List list1 = new ArrayList();
        Class a  = null;
        try {
            a = Class.forName("java.util.List");
            Class box = Class.forName("com.jerry.reflect.Box");
            Object box1 = box.newInstance();
            Method method = a.getDeclaredMethod("add",Object.class);
            Field f = box.getDeclaredField("id");
            f.setAccessible(true);
            f.set(box1,"dawdawadawdadada");
            System.out.println(f.get(box1));
            method.invoke(list1,"20");
            System.out.println(list1.get(0));
        } catch (ClassNotFoundException e) {
            e.printStackTrace();
        } catch (NoSuchMethodException e) {
            e.printStackTrace();
        } catch (IllegalAccessException e) {
            e.printStackTrace();
        } catch (InvocationTargetException e) {
            e.printStackTrace();
        } catch (NoSuchFieldException e) {
            e.printStackTrace();
        } catch (InstantiationException e) {
            e.printStackTrace();
        }

    }
}
